package com.qububu.play;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import com.qububu.utils.SystemConstants;

public class PlayInterceptor implements HandlerInterceptor {

	
	public void afterCompletion(HttpServletRequest arg0,
			HttpServletResponse arg1, Object arg2, Exception arg3)
			throws Exception {
		// TODO Auto-generated method stub
		
	}

	public void postHandle(HttpServletRequest arg0, HttpServletResponse arg1,
			Object arg2, ModelAndView arg3) throws Exception {
		// TODO Auto-generated method stub
		
	}

	public boolean preHandle(HttpServletRequest req, HttpServletResponse resp,
			Object obj) throws Exception {
		/*String repairPageUrl = req.getContextPath() + "/repair/play";
		resp.sendRedirect(repairPageUrl);*/

		String requestUrl = req.getRequestURI();
		
		if (requestUrl.equals(req.getContextPath() + "/play/article/writePosts") ) {
			if (req.getSession().getAttribute(SystemConstants.LOGINUSER_SESSION_NAME) == null) {
				resp.sendRedirect(req.getContextPath() + "/play/main");	
				return false;
			}
		}
		
		return true;
	}
	
}
